package org.szgb.console.sys.custom.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.szgb.console.utils.PageDto;
import org.szgb.core.base.entity.BeanEntity;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class SysCustomFormModel extends BeanEntity<SysCustomFormModel> {
    @Serial
    private static final long serialVersionUID = 1L;
    private String name;

    public SysCustomFormModel() {
    }

    public SysCustomFormModel(String id) {
        this.setId(id);
    }

    public SysCustomFormModel(SysCustomFormModel.SysCustomFormModelFindDto SysCustomFormModelFindDto){
        this.setId(SysCustomFormModelFindDto.getId());
        this.setName(SysCustomFormModelFindDto.getName());
        this.setPageDto(SysCustomFormModelFindDto.getPageDto());
    }

    public SysCustomFormModel(SysCustomFormModel.SysCustomFormModelSaveDto SysCustomFormModelSaveDto){
        this.setId(SysCustomFormModelSaveDto.id);
        this.setName(SysCustomFormModelSaveDto.name);
    }

    public SysCustomFormModel.SysCustomFormModelView toSysCustomFormModelView() {
        return new SysCustomFormModel.SysCustomFormModelView(this);
    }

    @Data
    @Schema(title = "自定义表单模板信息", description = "自定义表单模板信息")
    public static class SysCustomFormModelView {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "名称")
        private String name;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "创建时间")
        private LocalDateTime createdAt;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "更新时间")
        private LocalDateTime updatedAt;
        @Schema(description = "创建人id")
        private String createdById;
        @Schema(description = "创建人姓名")
        private String createdByName;
        @Schema(description = "更新人id")
        private String updatedById;
        @Schema(description = "更新人姓名")
        private String updatedByName;

        public SysCustomFormModelView(SysCustomFormModel SysCustomFormModel) {
            this.id = SysCustomFormModel.getId();
            this.name = SysCustomFormModel.getName();
            this.createdAt = SysCustomFormModel.getCreatedAt();
            this.updatedAt = SysCustomFormModel.getUpdatedAt();
            if (SysCustomFormModel.getCreatedBy() != null) {
                this.createdById = SysCustomFormModel.getCreatedBy().getId();
                this.createdByName = SysCustomFormModel.getCreatedBy().getName();
            }
            if (SysCustomFormModel.getUpdatedBy() != null) {
                this.updatedById = SysCustomFormModel.getUpdatedBy().getId();
                this.updatedByName = SysCustomFormModel.getUpdatedBy().getName();
            }
        }

        public static List<SysCustomFormModel.SysCustomFormModelView> getViewListFromList(List<SysCustomFormModel> SysCustomFormModelList) {
            return SysCustomFormModelList.stream().map(SysCustomFormModel.SysCustomFormModelView::new).toList();
        }
    }

    @Data
    @Schema(title = "自定义表单模板查询表单", description = "自定义表单模板查询参数")
    public static class SysCustomFormModelFindDto {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "名称")
        private String name;
        @Schema(description = "分页信息")
        private PageDto pageDto;

        public SysCustomFormModel toSysCustomFormModel() {
            return new SysCustomFormModel(this);
        }
    }

    @Data
    @Schema(title = "自定义表单模板保存表单", description = "自定义表单模板保存参数")
    public static class SysCustomFormModelSaveDto {
        @Schema(description = "id(如为空则为新增数据)")
        private String id;
        @Schema(description = "名称")
        private String name;

        public SysCustomFormModel toSysCustomFormModel() {
            return new SysCustomFormModel(this);
        }
    }
}
